package com.example.test_demo.myhashmap;

public class MyHashmap<K,V> {
	//容器大小
	private int capacity=16;
	//数组长度，初始值0
	private int size=0;
	//数组对象
	//private MyEntry<K, V>[] table;//能这样写吗
	private MyEntry[] table;
	//通过构造器初始化对象数组
	public MyHashmap(int capacity) {
		super();
		this.capacity = capacity;
		this.table=new MyEntry[capacity];
	}
	//无参构造，默认容器大小
	public MyHashmap() {
		super();
		this.table=new MyEntry[this.capacity];
	}
	//计算key的hash值
	public int hash(K key) {
		// TODO Auto-generated method stub
		if (key==null) {

			return 0;
		}
		//先计算hashcode
		int h = key.hashCode();
		//根据hashcode和容器大小计算索引值
		//h=h%capacity;//试试取模
		h^=h>>>capacity;
		return capacity;

	}
	public void put(K key,V value) {
		// TODO Auto-generated method stub
		if (key==null) {

		}
		int hash = hash(key);
		int index = hash&(capacity-1);
		//遍历索引对应的集合元素
		for (MyEntry<K, V> e = table[index]; e!=null; e=e.E) {
			if (e.index==hash&&(e.KEY==key||e.KEY.equals(key))) {
				V oldvalue=e.VALUE;
				e.VALUE=value;
			}

		}
		//扩容
		addEntry(key, value, index, hash);

	}
	public void addEntry(K key,V value, int index,int hash) {
		// TODO Auto-generated method stub
		MyEntry<K,V> entry = table[index];
		if (size==capacity) {

		}
	}


}
